import java.util.Arrays;

public class Sort {
    public static void heapSort(int[] array){
        for(int parent=((array.length)-1-1)/2;parent>=0;parent--){
            siftDown(array,parent);
        }
    }
    public static void siftDown(int[] array,int parent){
        int son=2*parent+1;
        while(son< array.length){
            while(son+1<array.length&&array[son]<array[son+1]){
                son++;
            }
            if(array[parent]<array[son]){
                swap(array,parent,son);
                parent=son;
                son=2*parent+1;
            }else{
                break;
            }
        }
    }
    public static void main(String[] args){
        int array[]={23,44,53,33,22,3};
        heapSort(array);
        System.out.println(Arrays.toString(array));
    }
    public static void swap(int[] array,int i,int j){
        int tmp=array[i];
        array[i]=array[j];
        array[j]=tmp;
    }
}
